<?php
namespace app\admin\controller;

use app\admin\model\User as UserModel;


class User extends BaseController
{
    public function index(){
        //分页
        $users=UserModel::order('id desc')->paginate(3);
        $this->assign('list', $users);
        return $this->fetch('index');

    }

    public function add(){

        return $this->fetch();
    }

    public function doadd(){

        $data=$this->request->param();
        $model = new UserModel();
        $res = $model->save($data);
        if($res){
            $this->success('添加成功','user/index');
        }
        else{
            $this->error('添加失败');
        }
    }

    public function edit($id=0){
        $row=UserModel::get($id);
        $this->assign('row',$row);
        return $this->fetch();

    }
    public function doedit(){
        $data=$this->request->param();
        $res=UserModel::update($data);
        if ($res) {
            $this->success('修改成功','user/index');
        }
        else {
            $this->error('修改失败');
        }
    }

    public function del($id=0)
    {
        $reg=UserModel::destroy($id);
        if ($reg) {
            $this->success('删除成功','user/index');
        }
        else {
            $this->error('删除失败');
        }

    }




}